package com.china.springServer.service.impl;

import com.china.springServer.listener.ZookeeperServiceListener;
import com.china.springServer.service.ServiceChangeListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;

/**
 * @fileName: AppRunner
 * @author: LmR
 * @createDate: 2023/10/21 22:28
 * @Desc:
 */
public class AppRunner implements CommandLineRunner {
    @Autowired
    private ZookeeperServiceListener serviceListener;

    @Override
    public void run(String... args) throws Exception {
        serviceListener.watchServices(new ServiceChangeListener() {
            // 监听服务变更
            @Override
            public void onServiceAdded(String serviceAddress) {
                // 服务上线
                System.out.println("service node up....");
            }

            @Override
            public void onServiceRemoved(String serviceAddress) {
                // 服务下线
                System.out.println("service node down....");
            }
        });
    }
}
